package com.happyass.show.controller;


import com.happyass.service.ExcelService;
import com.happyass.show.entity.Activity;
import com.happyass.show.entity.Addr;
import com.happyass.show.entity.Plan;
import com.happyass.show.entity.PlanActRel;
import com.happyass.show.service.ActivityService;
import com.happyass.show.service.PlanService;
import net.minidev.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

/**
 * TODO
 *
 * @author admin
 * @date 2021/1/7 14:02
 *
 * <P></P>
 **/

@Controller
@RequestMapping("/plan")
public class PlanController {

    @Autowired
    PlanService planService;
    @Autowired
    ActivityService activityService;
    @Autowired
    ExcelService excelService;

    //后台演出计划列表展示
    @RequestMapping("/planList")
    public String list(Model map, Plan plan){
        HashMap<String, Object> hm = planService.planList(plan);
        map.addAttribute("list",hm);
        return "show/plan/planIndex";
    }


    //后台演出计划 正在运行计划和历史计划  状态互换
    @RequestMapping("/planStatus")
    @ResponseBody
    public HashMap<String,Object> status(Plan plan, Integer planStatus){

        return planService.planStatus(plan.getPlanItem(),planStatus);
    }


    //后台演出计划新增界面跳转
    @RequestMapping("/plan")
    public String add(){
        return "show/plan/planAdd";
    }

    //后台演出计划查询所有可用的表演节目
    @RequestMapping("/actValue")
    @ResponseBody
    public JSONArray getAct(){
        return activityService.findActivity();
    }


    //后台演出计划新增
    @RequestMapping("/add")
    @ResponseBody
    public HashMap<String,Object> add(String activityId,String showWorkdayTime,String showWeekdayTime,String showStopWeekday,String planItem){
        return planService.planAdd(activityId,showWorkdayTime,showWeekdayTime,showStopWeekday,planItem);
    }

    //后台演出计划删除
    @RequestMapping("/del")
    @ResponseBody
    public HashMap<String, Object> del(String planItem){
        HashMap<String, Object> map = planService.planDel(planItem);
        return map;
    }

    //后台演出计划批量删除
    @RequestMapping("/delMany")
    @ResponseBody
    public HashMap<String, Object> delMany(String items){
        HashMap<String, Object> map = planService.plansDel(items);
        return map;
    }

    //后台演出计划搜索
    @RequestMapping("/planSearch")
    public String search(Model map, String searchKey, String searchValue, Plan plan){
        HashMap<String, Object> hm = planService.planSearch(searchKey, searchValue, plan);
        map.addAttribute("list",hm);
        if (hm.get("back")!=null){
            return "show/plan/planIndex";
        }else {
            return "show/plan/planSearch";
        }
    }

    //后台演出计划修改页面跳转
    @RequestMapping("/update")
    public String update(Model map,String planItem){
        map.addAttribute("pars",planService.update(planItem));
        return "show/plan/planUpdate";
    }

    //后台演出计划修改
    @RequestMapping("/updatePlan")
    @ResponseBody
    public HashMap<String, Object> update(String activityId,String showWorkdayTime,String showWeekdayTime,String showStopWeekday,String planItem){
        return planService.planUpdate(activityId,showWorkdayTime,showWeekdayTime,showStopWeekday,planItem);
    }

    //后台演出计划具体内容查看
    @RequestMapping("/detail")
    public String detail(String planItem,Model map){
        HashMap<String, Object> all = planService.planDetail(planItem);
        map.addAttribute("dayMap",all.get("dayMap"));
        map.addAttribute("nightMap",all.get("nightMap"));
        map.addAttribute("planItem",planItem);
        return "show/plan/planDetail";
    }

    //后台演出计划excel导出
    @RequestMapping("/planExcel")
    public void excel(HttpServletResponse response, String planItem) {
        excelService.planExcel(response,planItem);
    }

    //后台演出计划 回收站
    @RequestMapping("/retrieve")
    public String retrieve(Model map,Plan plan){
        map.addAttribute("list",planService.findRetrieve(plan));
        return "show/plan/planRetrieve";
    }

    //后台演出计划恢复
    @RequestMapping("/resume")
    @ResponseBody
    public HashMap<String, Object> resume(String planItem){
        HashMap<String, Object> map = planService.planRes(planItem);
        return map;
    }

    //后台演出计划批量恢复
    @RequestMapping("/resumeMany")
    @ResponseBody
    public HashMap<String, Object> resumes(String items){
        HashMap<String, Object> map = planService.plansRes(items);
        return map;
    }

    //后台演出计划搜索
    @RequestMapping("/retrieveSearch")
    public String retrieveSearch(Model map,String searchKey,String searchValue,Plan plan){
        HashMap<String, Object> hm = planService.retrieveSearch(searchKey, searchValue, plan);
        map.addAttribute("list",hm);
        if (hm.get("back")!=null){
            return "show/plan/planRetrieve";
        }else {
            return "show/plan/planRetrieveSearch";
        }
    }
}
